<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="/js/jquery-2.1.1.min.js"></script>
    <script src="/js/json.js"></script>
    <script src="https://cdn.bootcss.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
    <link href="https://cdn.bootcss.com/twitter-bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet" />
    <script>


        function stop(t){
            $.post(
                "task/destroy",
                {task:t},
                function(data){
                    if(data['code']==200){
                        alert("成功");
                    }else{
                        alert("失败");
                    }
                },
                "json"
            );
        }
        function progress(t){
            $.post(
                "task/progress",
                {task:t},
                function(data){
                    if(data['code'] == 200){
                        var rate = (data['data'])*100;

                        $("#progress").attr("style","width: "+rate+"%;");
                    }
                },
                "json"
            );
        }

        function data(t){
            $.post(
                "task/data",
                {task:t},
                function(data){
                    if(data['code'] == 200){
                        var arr = data['data'];
                        var base = (arr['data']);
                        $("#base").val(base);
                        $("#vulns").val(vulns);
                    }else{
                        alert(data['msg']);
                    }
                },
                "json"
            );
        }

    </script>
    <script>

        datamap = new Map()
        task = ""
        $(function () {

            getdata()

            $("#create_button").click(function () {
                $.ajax({
                    url:"task/create",
                    type:"post",
                    dataType:'json',
                    data: $('#form_create').serialize(),
                    success:function (data) {
                        if (data.code==200){
                            var md5 = data.data;
                            $.post(
                                "task/start",
                                {task:md5},
                                function (text) {
                                    if (text.code==200){
                                        alert(md5+"正在扫描请等待");
                                    }else{
                                        alert(text.msg);
                                    }
                                },
                                "json"
                            );

                        }else{
                            alert(data.msg);
                        }
                    }
                });
            });

        });

        function getdata(){
            $.get(
                "task/find",
                function (data) {
                    data = data.data
                    $("tbody").html("");
                    for (i in data){

                        var item = data[i]

                        if (!datamap.has(item.taskMd5)){
                            datamap.set(item.taskMd5,item.baseInfo)
                        }

                        console.log(item)

                        var tmp = "<tr>\n" +
                            "                            <td>\n" +
                            "                                "+item.id+"\n" +
                            "                            </td>\n" +
                            "                            <td>\n" +
                            "                                "+item.taskName+"\n" +
                            "                            </td>\n" +
                            "                            <td>\n" +
                            "                                "+item.status+"\n" +
                            "                            </td>\n" +
                            "                            <td>\n" +
                            "                                "+item.target+"\n" +
                            "                            </td>\n" +
                            "                            <td>\n" +
                            "                                <a data-toggle=\"tab\" href='#view'><button onclick=view('"+item.taskMd5+"')>查看</button></a>\n" +
                            "                                <button onclick=stop('"+item.taskMd5+"')>停止</button>\n" +
                            "                            </td>\n" +
                            "                        </tr>"


                        $("tbody").append(tmp)

                    }

                },
                "json"
            )
        }

        function view(id) {
            task = id;

            var info = datamap.get(id);

            var obj = JSON.parse(info);

            var assets = obj.assets
            var ipInfo = obj.ipInfo
            var items = obj.items
            var senseInfo = obj.senseInfo

            $("#systemInfo").text(formatJson(JSON.stringify(ipInfo)));


            $("#childDomain").text(JSON.stringify(assets.childDomain))

            $("#icpSite").text(JSON.stringify(assets.icpSite))

            $("#holdSite").text("")
            for(i in assets.holdSite){
                $("#holdSite").append(assets.holdSite[i]+"\n")
            }

            $("#serverSite").text("")
            for(i in assets.serverSite){
                $("#serverSite").append(assets.serverSite[i]+"\n")
            }


            for (i in obj.senseInfo){
                $("#"+i).append(obj.senseInfo[i])
            }

            for(tar in obj.items){


                var tmp =$('<div id="'+tar+'"><h3>'+tar+'</h3><hr/></div>');

                var a = $("<pre></pre>")

                var item = obj.items[tar];

                var systemInfo = item.systemInfo;
                var vulns = item.vulns;

                for (i in systemInfo){

                    var x = systemInfo[i]
                    a.append(i +" => "+formatJson(JSON.stringify(x))+"\n");

                }
                tmp.append(a)
                var vuldom =$('<div><h4>漏洞信息</h4></div>')
                for (v in vulns){

                    var vul = vulns[v]
                    var affectsDetail = vul["affectsDetail"]
                    var affectsUrl = vul["affectsUrl"]
                    var description = vul["description"]
                    var level = vul["level"]
                    var recommendation = vul["recommendation"]
                    var references = vul["references"]
                    var request = vul["request"]
                    var vulName = vul["vulName"]
                    var vulType = vul["vulType"]

                    var color;
                    switch(level){
                        case 0:
                            color = "green"
                            break
                        case 1:
                            color = "blue"
                            break
                        case 2:
                            color = "orange"
                            break
                        case 3:
                            color = "red"
                            break
                    }

                    var aaaa= $('<h5><font color="'+color+'">'+vulName+'</font></h5>\n' +
                        '        <p>漏洞地址: '+affectsUrl+'</p>\n' +
                        '        <p>影响详情: '+affectsDetail+'</p>\n' +
                        '        <p>修复建议: '+recommendation+'</p>\n' +
                        '        <p>相关链接: '+references+'</p>\n' +
                        '        <p>漏洞等级: '+level+'</p>'+
                        '        <p>请求: <pre>'+request+'</pre></p>');
                    vuldom.append(aaaa)

                }
                console.log(vuldom)
                tmp.append(vuldom)
                $("#secdata").html("")
                $("#secdata").append(tmp)

            }


        }

        setInterval("getdata",60000);

    </script>
</head>
<body>
<div class="container-fluid">
    <h2 class="page-header">TrackRay</h2>
    <div class="tabbable tabs-left">
        <ul class="nav nav-tabs">
            <li class="active"><a href="#create" data-toggle="tab">创建任务</a></li>
            <li><a href="#task" data-toggle="tab">任务列表</a></li>
            <li><a href="#view" data-toggle="tab">任务详情</a></li>
        </ul>

        <!--
              选项卡的内容定义
            -->
        <div class="tab-content">
            <div class="tab-pane " id="view">
                <div class="col-md-12 column">
                    <div class="panel-group" id="panel-zcxx">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <a class="panel-title" data-toggle="collapse" data-parent="#panel-zcxx" href="#panel-element-zcxx"><h2>资产信息</h2></a>
                            </div>
                            <div id="panel-element-zcxx" class="panel-collapse collapse">
                                <div class="panel-body">
                                    <div>
                                        <h3>子域名</h3>
                                        <hr />
                                        <pre id="childDomain"></pre>
                                    </div>
                                    <div>
                                        <h3>持有域名</h3>
                                        <hr />
                                        <pre id="holdSite"></pre>
                                    </div>
                                    <div>
                                        <h3>备案持有域名</h3>
                                        <hr />
                                        <pre id="icpSite"></pre>
                                    </div>
                                    <div>
                                        <h3>同服网站</h3>
                                        <hr />
                                        <pre id="serverSite"></pre>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <a class="panel-title" data-toggle="collapse" data-parent="#panel-xtxx" href="#panel-element-xtxx"><h2>系统信息</h2></a>
                            </div>
                            <div id="panel-element-xtxx" class="panel-collapse collapse">
                                <div class="panel-body">
                                    <div>
                                        <h3>系统信息</h3>
                                        <hr />
                                        <pre id="systemInfo"></pre>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <a class="panel-title" data-toggle="collapse" data-parent="#panel-mgxx" href="#panel-element-mgxx"><h2>敏感信息</h2></a>
                            </div>
                            <div id="panel-element-mgxx" class="panel-collapse collapse">
                                <div class="panel-body">
                                    <div>
                                        <h3>邮箱</h3>
                                        <hr />
                                        <pre id="email"></pre>


                                        <h3>手机号</h3>
                                        <hr />
                                        <pre id="tel"></pre>

                                        <h3>号码</h3>
                                        <hr />
                                        <pre id="num"></pre>
                                        <h3>其他</h3>
                                        <hr />
                                        <pre id="other"></pre>
                                    </div>
                                </div>
                            </div>
                        </div>


                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <a class="panel-title" data-toggle="collapse" data-parent="#panel-aqrd" href="#panel-element-aqrd"><h2>安全弱点</h2></a>
                            </div>
                            <div id="panel-element-aqrd" class="panel-collapse collapse">
                                <div class="panel-body">
                                    <div id="secdata">



                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>


                </div>
            </div>
            <div class="tab-pane " id="task">
                <div class="col-md-12 column">
                    <table class="table table-bordered table-hover">
                        <thead>
                        <tr>
                            <th> 编号 </th>
                            <th> 名称 </th>
                            <th> 状态 </th>
                            <th> 目标 </th>
                            <th> 操作 </th>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                    <button onclick="getdata()">刷新</button>
                </div>
            </div>
            <div class="tab-pane active" id="create">
                <div class="col-md-12 column">
                    <form id="form_create" role="form">
                        <div class="form-group">
                            <label>任务名</label>
                            <input class="form-control" type="text" name="name" value="test" />
                            <label>扫描地址</label>
                            <input class="form-control" type="text" name="target" value="http://testphp.vulnweb.com/" />
                            <label>Cookie</label>
                            <input class="form-control" type="text" name="cookie" />
                            <label>线程数(最大50)</label>
                            <input class="form-control" type="text" name="thread" value="20" />
                            <label>爬虫广度(最大500)</label>
                            <input class="form-control" type="text" name="spiderMax" value="300" />
                            <label>爬虫深度(写2就行)</label>
                            <input class="form-control" type="text" name="spiderDeep" value="2" />
                            <label>最大扫描时间(毫秒)</label>
                            <input class="form-control" type="text" name="timeMax" value="100000" />
                            <label>代理池(json格式)</label>
                            <textarea class="form-control" name="proxy"></textarea>
                        </div>
                        <div class="form-group">
                            <label>扫描规则</label>
                            <label><input type="checkbox" value="true" name="rule.crawler" />网页爬虫</label>
                            <label><input type="checkbox" value="true" name="rule.sense" />资产扫描</label>
                            <label><input type="checkbox" value="true" name="rule.port" />端口扫描</label>
                            <label><input type="checkbox" value="true" name="rule.finger" />指纹识别</label>
                            <label><input type="checkbox" value="true" name="rule.childdomain" />子域名</label>
                            <label><input type="checkbox" value="true" name="rule.fuzzdir" />目录扫描</label>
                            <label><input type="checkbox" value="true" name="rule.attack" />漏洞模块攻击</label>
                            <label><input type="checkbox" value="true" name="rule.thorough" />深度扫描</label>
                            <div class="checkbox">
                            </div>
                        </div>
                        <button id="create_button" type="button" class="btn btn-default">开始</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>